package physics;

public class Shape implements Cloneable{
	protected static final Vector nullVec = new Vector(0, 0);
	
	protected Vector posn = nullVec;
	protected Vector vel = nullVec;
	protected Vector acc = nullVec;
	protected double gravity = 0;
	protected boolean fixed = false;
	protected double mass = 1;
	
	public Shape() {
		posn = new Vector(0, 0);
		vel = new Vector(0, 0);
		acc = new Vector(0, -1);
		gravity = 0;
		fixed = false;
	}
	
	public Shape(Vector posn, Vector vel, Vector acc, double mass, 
			double grav, boolean fixed) {
		this.posn = posn;
		this.vel = vel;
		this.acc = acc;
		this.mass = mass;
		gravity = grav;
		this.fixed = fixed;
		if(fixed) mass = 500000000;
	}
	
	public Vector getPosn() {
		return posn;
	}

	public void setPosn(Vector posn) {
		this.posn = posn;
	}

	public Vector getVel() {
		return vel;
	}

	public void setVel(Vector vel) {
		this.vel = vel;
	}

	public double getMass() {
		return mass;
	}

	public void setMass(double mass) {
		this.mass = mass;
	}

	public void setGravity(double gravity) {
		this.gravity = gravity;
	}

	public void setFixed(boolean fixed) {
		this.fixed = fixed;
	}

	public Vector getAcc() {
		return acc;
	}

	public void setAcc(Vector acc) {
		this.acc = acc;
	}

	public double getGravity() {
		return gravity;
	}

	public void setGravity(float gravity) {
		this.gravity = gravity;
	}

    public boolean isFixed() {
    	return fixed;
    }
    
    public boolean isCircle() {
    	return this instanceof Circle;
    }
    
    public boolean isRectangle() {
    	return this instanceof Rectangle;
    }
    
    public boolean isPolygon() {
    	return this instanceof Polygon;
    }
    
    public void changePosn(Vector offset) {
    	this.posn = this.posn.add(offset);
    }
    
    public Shape move(Vector offset) {
    	try {
			Shape copy = (Shape) this.clone();
			copy.changePosn(offset);
			return copy;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
    	return null;
    }
    
    public boolean equals(Object other) {
    	if(other instanceof Shape) {
    		return this.posn.equals(((Shape)other).posn) && 
    				this.vel.equals(((Shape)other).vel) &&
    				this.acc.equals(((Shape)other).acc) &&
    				this.mass == ((Shape)other).mass;
    	} else {
    		return false;
    	}
    }
}
